-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Fix DomCrawler html dumping example. #2309
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@@ -190,7 +190,7 @@ and :phpclass:`DOMNode` objects: | |||
$html = ''; | |||
|
|||
foreach ($crawler as $domElement) { | |||
$html.= $domElement->ownerDocument->saveHTML(); | |||
$html.= $domElement->ownerDocument->saveHTML($domElement); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
while it is not your mistake, could you please add a space between $html
and .=
?
👍 |
Done. |
Some more research turned out that this sidebar give us an example on how to get the HTML of the complete |
I'm not sure that you got it correctly. Here is an example where the crawler represents all b tags in the document. Current doc example outputs the whole document twice (like we didn't filter the crawler). After my fix it prints 2 b tags. use Symfony\Component\DomCrawler\Crawler;
$crawler = new Crawler('<b>1</b><i>2</i><b>3</b>');
$html = '';
foreach ($crawler->filter('b') as $domElement) {
$html.= $domElement->ownerDocument->saveHTML();
}
echo $html; <_root><html><body><b>1</b><i>2</i><b>3</b></body></html></_root>
<_root><html><body><b>1</b><i>2</i><b>3</b></body></html></_root> use Symfony\Component\DomCrawler\Crawler;
$crawler = new Crawler('<b>1</b><i>2</i><b>3</b>');
$html = '';
foreach ($crawler->filter('b') as $domElement) {
$html .= $domElement->ownerDocument->saveHTML($domElement);
}
echo $html; <b>1</b><b>3</b> |
Ah, I understand what you mean. You're correct. 👍 |
Fix DomCrawler html dumping example.
Awesome guys, thanks! |
Current example collects HTML of the whole documents instead of required nodes.